export const URL = {
  getUrl: (base_url, params) => {
    var result = base_url,
      query_array = [];

    for (var key in params) {
      query_array.push(key + "=" + params[key]);
    }

    if (query_array.length > 0) {
      result = result + "?" + query_array.join('&');
    }

    return result;
  }
}

export const CURRENCY = {
  enum: {
    'USD': {
      text: "美元",
      label: '$',
      type: '美元'
    },
    'RMB': {
      text: "元",
      label: '¥',
      type: '人民币'
    },
    'CNY': {
      text: "元",
      label: '¥'
    },
    'EUR': {
      text: '欧元',
      label: '€',
      type: '欧元'
    }
  },
  format (str) {
    if (!str) return 0;
    if (str.toString().indexOf('.') == -1) {
      return str.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
    }
    str = str.toString().split('.');
    str[0] = str[0] || '0';
    str[1] = str[1] ? ('.' + str[1]) : '';
    return str[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + str[1];
  },

  getUnit (type) {
    return this.enum[type] || this.enum['RMB']
  }
}